package org.edu.modules.sbzc.fund.service.impl;

import cn.hutool.core.convert.Convert;
import org.edu.common.base.BasePageDto;
import org.edu.common.base.BaseServiceImpl;
import org.edu.common.utils.ConvertUtils;
import org.edu.common.base.BaseServiceImpl;
import org.edu.modules.sbzc.fund.dto.VeSbzcZcAssetDto;
import org.edu.modules.sbzc.fund.mapper.VeSbzcZcAllocateMapper;
import org.edu.modules.sbzc.fund.entity.VeSbzcZcAllocate;
import org.edu.modules.sbzc.fund.dto.VeSbzcZcAllocateDto;
import org.edu.modules.sbzc.fund.service.VeSbzcZcAllocateService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.edu.modules.sbzc.fund.service.VeSbzcZcAssetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 实现类
 */
@Service
public class VeSbzcZcAllocateServiceImpl extends BaseServiceImpl<VeSbzcZcAllocate, VeSbzcZcAllocateMapper> implements VeSbzcZcAllocateService {

    /**
     * VeSbzcZcAssetService
     */
    @Autowired
    private VeSbzcZcAssetService veSbzcZcAssetService;

    public IPage<VeSbzcZcAllocateDto> pageDto(BasePageDto page, @Param(Constants.WRAPPER) Wrapper queryWrapper){
        return mapper.pageDto(page,queryWrapper);
    }
    /**
    * 查询实体类
    */
    public VeSbzcZcAllocateDto findDtoById(String id) {
        VeSbzcZcAllocate entity = super.findById(id);
        VeSbzcZcAllocateDto dto = ConvertUtils.convertToDto(entity, VeSbzcZcAllocateDto.class);
        return dto;
    }

    /**
    * 新增或者修改
    */
    public void insertOrUpdate(VeSbzcZcAllocateDto dto,Boolean isAdd){
        if(isAdd){
            super.insert(dto);
        }else{
            super.update(dto);
        }
        //调拨更改归属部门，未对接用户部门数据，先注释掉
//        VeSbzcZcAssetDto veSbzcZcAssetDto = veSbzcZcAssetService.findDtoById(Convert.toStr(dto.getAssetId()));
//        veSbzcZcAssetDto.setDeptOwn(Convert.toStr(dto.getAllocateDept()));
//        //更新归属部门
//        veSbzcZcAssetService.save(veSbzcZcAssetDto);
    }

}
